package cfengMiddleware.server.controller;


import CfengMiddleWare.model.entity.MidGoods;
import cfengMiddleware.server.service.MidGoodsService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * <p>
 * 商品信息表 前端控制器
 * 缓存穿透演示
 * </p>
 *
 * @author cfeng
 * @since 2022-09-12
 */

@Slf4j
@RestController
@RequiredArgsConstructor
@RequestMapping("/mid-goods")
public class MidGoodsController {

    private final MidGoodsService goodsService;

    /**
     * 获取热销商品信息 --- 商品编号
     */
    @GetMapping("/info")
    public ResponseEntity<MidGoods> getGoods(@RequestParam String goodsCode) {
        //根据商品编号查看商品
        MidGoods midGoods = null;
        try {
            midGoods = goodsService.getGoodsInfo(goodsCode);
        } catch (Exception e) {
            return new ResponseEntity("There is a error", HttpStatus.BAD_GATEWAY);
        }
        return ResponseEntity.ok(midGoods);
    }
}
